Load datasets

GDP_per_Capita <- read_csv2("data/GDP per capita (current US$).csv")
## ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
## Rows: 6 Columns: 66
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr  (1): Country Name
## dbl (64): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
## lgl  (1): 2024
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Hisorical_Population <- read_csv2("data/Historical population.csv")
## ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
## Rows: 10 Columns: 69── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr  (4): Series Name, Series Code, Country Name, Country Code
## dbl (52): 1970 [YR1970], 1971 [YR1971], 1972 [YR1972], 1973 [YR1973], 1974 [...
## num (12): 1960 [YR1960], 1961 [YR1961], 1962 [YR1962], 1963 [YR1963], 1964 [...
## lgl  (1): 2024 [YR2024]
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Life_expectancy <- read_csv("data/life-expectancy-at-birth-including-the-un-projections.csv")
## Rows: 604 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Entity, Code
## dbl (3): Year, Life expectancy - Sex: all - Age: 0 - Variant: estimates, Lif...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
GDP <- read_csv2("data/GDP.csv")
## ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
## Rows: 9 Columns: 66── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr  (1): Country Name
## num (64): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
## lgl  (1): 2024
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Net_migration <- read_csv2("data/Net migration.csv")
## ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
## Rows: 10 Columns: 66── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr  (1): Country Name
## dbl (65): 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ...
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Child_mortality_under_5 <- read_csv("data/Transformed_Børnedødelighed (1).csv")
## Rows: 5 Columns: 76
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): Country Name
## dbl (75): 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

GDP

# Convert from wide to long format
gdp_with_year <- GDP %>%
  pivot_longer(cols = -`Country Name`, names_to = "Year", values_to = "GDP") %>%
  mutate(Year = as.numeric(Year)) %>% 
  na.omit(GDP) %>%
  mutate(GDP = GDP / 1e9)

# Creating the ggplot
GDP_by_Country <- ggplot(gdp_with_year, aes(x = Year, y = GDP, color = `Country Name`)) +
  geom_line(size=1.5) +
  labs(title = "GDP Over Time by Country",
       x = "Year",
       y = "GDP (in billions)", 
       color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20), legend.title = element_text(size = 14),legend.text = element_text(size = 12))  
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
GDP_by_Country

selected_countries <- c("Greenland", "Faroe Islands", "Iceland")

gdp_G_F_I <- gdp_with_year %>%
  filter(`Country Name` %in% selected_countries)


GDP_Greenland_FaroeIslands_Iceland <- ggplot(gdp_G_F_I, aes(x = Year, y = GDP, color = `Country Name`)) +
  geom_line(size=1.5) +
  labs(title = "GDP Greenland, Faroe Islands, and Iceland",
       x = "Year",
       y = "GDP (in billions)",
       color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20),legend.title = element_text(size = 14),legend.text = element_text(size = 12))

GDP_Greenland_FaroeIslands_Iceland

###Only Greenland

selected_countries_2 <- c("Greenland")

GDP_Greenland <- gdp_with_year %>%
  filter(`Country Name` %in% selected_countries_2)

# Creating the ggplot
GDP_Greenland <- ggplot(GDP_Greenland, aes(y=GDP, x=Year, color=`Country Name`)) +
  geom_line(size=1.5) +
  labs(title="GDP Greenland", x="Year", y="GDP (in billions)", color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20),legend.title = element_text(size = 14),legend.text = element_text(size = 12))+
  scale_color_manual(values = c("Greenland" = "springgreen3"))

GDP_Greenland

Collecting the graphs

# Using the patchwork package to arrange the plots
Collected_GDP<- GDP_by_Country | GDP_Greenland_FaroeIslands_Iceland / GDP_Greenland &
  scale_x_continuous(limits = c(1960, 2023))

Collected_GDP <- Collected_GDP + 
  plot_annotation(title = "GDP Over Time by Country")

Collected_GDP

Moveable graphs

Loading libraries for animation

ggplotly(GDP_by_Country)
animated_plot <- GDP_by_Country +
  transition_reveal(Year) +
  labs(title = 'GDP Over Time by Country: 1960-2021')

GDP_animated <- animate(animated_plot, nframes = 100, fps = 10,
renderer = gifski_renderer())
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
#anim_save("GNP_2.gif", animation = GDP_animated)

GDP_animated

ggplotly(GDP_Greenland_FaroeIslands_Iceland)
animated_plot <- GDP_Greenland_FaroeIslands_Iceland +
  transition_reveal(Year) +
  labs(title = 'GDP Over Time by Country: 1960-2021')

GDP_animated_Greenland_FaroeIslands_Iceland <- animate(animated_plot, nframes = 100, fps = 10,
renderer = gifski_renderer())
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
#anim_save("GDP_animated_Greenland_FaroeIslands_Iceland_2.gif", animation = GDP_animated_Greenland_FaroeIslands_Iceland)

GDP_animated_Greenland_FaroeIslands_Iceland

#GDP per Capita

# Convert from wide to long format
GDP_Capita_year <- GDP_per_Capita %>%
  pivot_longer(cols = -`Country Name`, names_to = "Year", values_to = "GDP per Capita") %>%
  mutate(Year = as.numeric(Year)) %>% 
  na.omit(GDP)

# Creating the ggplot
GDP_Capita_year <- ggplot(GDP_Capita_year, aes(x = Year, y = `GDP per Capita`, color = `Country Name`)) +
  geom_line(size=1.5) +
  labs(title = "GDP per Capita Over Time by Country",
       x = "Year",
       y = "GDP per Capita (current US dollars)", 
       color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20), legend.title = element_text(size = 14),legend.text = element_text(size = 12))

GDP_Capita_year

ggplotly(GDP_Capita_year)

Life Expectanty

head(Life_expectancy)
## # A tibble: 6 × 5
##   Entity  Code   Year Life expectancy - Sex: all - Age:…¹ Life expectancy - Se…²
##   <chr>   <chr> <dbl>                               <dbl>                  <dbl>
## 1 Denmark DNK    1950                                70.3                     NA
## 2 Denmark DNK    1951                                70.9                     NA
## 3 Denmark DNK    1952                                70.8                     NA
## 4 Denmark DNK    1953                                71.2                     NA
## 5 Denmark DNK    1954                                71.3                     NA
## 6 Denmark DNK    1955                                71.9                     NA
## # ℹ abbreviated names:
## #   ¹​`Life expectancy - Sex: all - Age: 0 - Variant: estimates`,
## #   ²​`Life expectancy - Sex: all - Age: 0 - Variant: medium`
Life_expectancy_with_year <- Life_expectancy %>% 
  filter(Year <= "2023") %>%  
  mutate(Year = as.numeric(Year), `Life expectancy - Sex: all - Age: 0 - Variant: estimates` =as.numeric(`Life expectancy - Sex: all - Age: 0 - Variant: estimates`)) %>% 
  rename(Life_expectancy_data = `Life expectancy - Sex: all - Age: 0 - Variant: estimates`)

# Creating the ggplot
Life_expectancy_by_birth <- ggplot(Life_expectancy_with_year, aes(x=Year, y= Life_expectancy_data, color=Entity)) +
  geom_line(size=1.5) +
  labs(title="Life Expectancy at Birth", x="Year", y="Life Expectancy (in years)", color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20),legend.title = element_text(size = 14),legend.text = element_text(size = 12))

Life_expectancy_by_birth

Moveable graphs

ggplotly(Life_expectancy_by_birth)
animated_plot_LE <- Life_expectancy_by_birth +
  transition_reveal(Year) +
  labs(title = 'Life expectancy at birth: 1950-2023')

Life_expectancy_by_birth_animated <- animate(animated_plot_LE, nframes = 100, fps = 10, renderer = gifski_renderer())
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
#anim_save("Life_expectancy_by_birth_animated_2.gif", animation = Life_expectancy_by_birth_animated)

Life_expectancy_by_birth_animated

Child Mortality

Child_mortality <- Child_mortality_under_5 %>%
  pivot_longer(cols = -`Country Name`, names_to = "Year", values_to = "Child Mortality") %>%
  mutate(Year = as.numeric(Year)) %>% 
  na.omit(Child_mortality_under_5)

# Creating the ggplot
Child_mortality_5 <- ggplot(Child_mortality, aes(x=Child_mortality$Year, y= `Child Mortality`, color= `Country Name`)) +
  geom_line(size=1.5) +
  labs(title="Child mortality under 5", x="Year", y="Child mortality (per 1000)", color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20),legend.title = element_text(size = 14),legend.text = element_text(size = 12))


Child_mortality_5
## Warning: Use of `Child_mortality$Year` is discouraged.
## ℹ Use `Year` instead.

Moveable graphs

ggplotly(Child_mortality_5)
## Warning: Use of `Child_mortality$Year` is discouraged.
## ℹ Use `Year` instead.
animated_plot_LE <- Child_mortality_5 +
  transition_reveal(Year) +
  labs(title = 'Child mortality under 5')

Child_mortality_under_5_animated <- animate(animated_plot_LE, nframes = 100, fps = 10, renderer = gifski_renderer())
## Warning: Use of `Child_mortality$Year` is discouraged.
## ℹ Use `Year` instead.
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
#anim_save("Child_mortality_under_5_animated.gif", animation = Child_mortality_under_5_animated)

Child_mortality_under_5_animated

Net Migration

Net_migratuion_with_year <- Net_migration %>%
  pivot_longer(cols = -`Country Name`, names_to = "Year", values_to = "Net migration") %>%
  mutate(Year = as.numeric(Year)) %>% 
  na.omit(Net_migration)

# Creating the ggplot
Net_migration_year <- ggplot(Net_migratuion_with_year, aes(y= `Net migration`, x= Year, color= `Country Name`)) +
  geom_line(size=1.5) +
  labs(title="Net Migration", x="Year", y="Net Migration", color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20),legend.title = element_text(size = 14),legend.text = element_text(size = 12))

Net_migration_year

Only Greenland

selected_countries_2 <- c("Greenland")

Net_migration_Greenland <- Net_migratuion_with_year %>%
  filter(`Country Name` %in% selected_countries_2)

# Creating the ggplot
Net_migration_only_Greenland <- ggplot(Net_migration_Greenland, aes(y= `Net migration`, x= Year, color= `Country Name`)) +
  geom_line(size=1.5) +
  labs(title="Net Migration Greenland", x="Year", y="Net Migration", color = "Country") +
  theme_minimal()+
  theme(plot.title = element_text(size = 20),legend.title = element_text(size = 14),legend.text = element_text(size = 12))+
  scale_color_manual(values = c("Greenland" = "springgreen3"))


Net_migration_only_Greenland

###Collected Graph

# Using the patchwork package to arrange the plots
Collected_Net_migration <- Net_migration_year | Net_migration_only_Greenland &
  scale_x_continuous(limits = c(1960, 2023))

Collected_Net_migration  <- Collected_Net_migration + 
  plot_annotation(title = "Net Migration")

Collected_Net_migration
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_line()`).

Moveable graphs

ggplotly(Net_migration_year)
ggplotly(Net_migration_only_Greenland)
animated_plot_LE <- Net_migration_year +
  transition_reveal(Year) +
  labs(title = 'Net Migration')

Net_migration_animated <- animate(animated_plot_LE, nframes = 100, fps = 10, renderer = gifski_renderer())
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
#anim_save("Net_migration_animated.gif", animation = Net_migration_animated)

Net_migration_animated

animated_plot_LE <- Net_migration_only_Greenland +
  transition_reveal(Year) +
  labs(title = 'Net Migration Greenland')

Net_migration_Greenland_animated <- animate(animated_plot_LE, nframes = 100, fps = 10, renderer = gifski_renderer())
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
#anim_save("Net_migration_Greenland_animated.gif", animation = Net_migration_Greenland_animated)

Net_migration_Greenland_animated